<%@ page language="java" contentType="text/html; charset=UTF8" pageEncoding="UTF8"%>
<%@ page import="java.util.*" %>
<%@ page import="bcnet.service.PriceHistoryService" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
	String code = request.getParameter("code");
	String numberOfStockString = request.getParameter("numberOfStock");
	String buyPriceString = request.getParameter("buyPrice");
	String buyDateString = request.getParameter("buyDate");
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	
	PriceHistoryService priceHistoryService = new PriceHistoryService();
	
	if(code == null){
		priceHistoryService.getBoughtCodeList();
	}
	else {
		int numberOfStock = Integer.parseInt(numberOfStockString);
		double buyPrice = Double.parseDouble(buyPriceString);
		Date buyDate = sdf.parse(buyDateString);
		
		
		priceHistoryService.addBoughtCode(code, numberOfStock, buyPrice, buyDate);
	}

%>

<form action="addBoughtCode.jsp" method="post">
 		<label style="font-size:22px;">Add Bought Code</label>
 		<br/>
        <label for="code">Code:</label>  
        <input type="text" id="code" name="code" placeholder="code" required autofocus >
        <br/>
        <label for="code">Number Of Stock:</label>  
        <input type="text" id="numberOfStock" name="numberOfStock" placeholder="numberOfStock" required >
        <br/>
        <label for="code">Buy Price:</label>  
        <input type="text" id="buyPrice" name="buyPrice" placeholder="buyPrice" required >
		<br/>
        <label for="code">Buy Date:</label>  
        <input type="text" id="buyDate" name="buyDate" placeholder="buyDate yyyy-mm-dd" required >

		<button type="submit">Update</button>  		
	 </form>  
